import os
import shutil

from curl_cffi import requests
import re

root = "static/彼岸图库/"
if os.path.exists(root):
    shutil.rmtree(root)
os.makedirs(root)
url = "https://pic.netbian.com/"
headers = {
'user-agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/139.0.0.0 Safari/537.36',
'referer':'https://www.kdocs.cn/'
}
response = requests.get(url, headers=headers)
html = response.content.decode('GBK')
items = re.findall(r'<a href="(.*?)".*?><span><img src="(.*?)" alt="(.*?)" />', html, re.S)
for item in items:
    title = item[2]
    thumb_url = f"https://pic.netbian.com/{item[1]}"
    headers.update({
        'referer':url,
    })
    thumb_response = requests.get(thumb_url, headers=headers)
    with open(f"{root}/{title}_thumb.jpg", "wb") as f:
        f.write(thumb_response.content)

